Skip to main content

Template strings

You are already aware that you can create strings with double or single quotes, however these strings do not support interpolation.

At this situation we use template string method.

The template string start and end with a back tick(``).

console.log(`This is JavaScript`); // This is JavaScript

Multiline strings

Multiline strings are possible in template strings whereas it is not possible while using single quotes and double quotes.

let sample = `This is an
illustration of multline
string`;

console.log(sample);
// This is an
// illustration of multline
// string

String interpolation

Interpolation is possible with template strings. This means you could write a variable in your string and get its value.

You wrap your variable name inside a dollar($) sign and curly braces({}).

For example:

let language = "JavaScript";
console.log(`This is ${language}`); // This is JavaScript